// 修改密码
<template>
  <Form :model="formItem" :label-width="110">
    <FormItem label="添加配送方式">
      <Row style="margin-bottom:10px;">
        <Col span="">
        <Button type="primary" size="large" @click="modal1 = true">添加</Button>
        </Col>
        <Modal v-model="modal1" title="配送方式" @on-ok="addPsfs" @on-cancel="cancel1">
          <Input v-model="psfs" placeholder=""></Input>
        </Modal>
      </Row>
      <Row>
        <Col span="">
        <Table border :columns="columns8" :data="data7"></Table>
        </Col>
      </Row>
    </FormItem>
    <FormItem label="添加配送区域">
      <Row style="margin-bottom:10px;">
        <Col span="">
        <Button type="primary" size="large" @click="modal2 = true">添加</Button>
        </Col>
        <Modal v-model="modal2" title="地区名称" @on-ok="addAreas" @on-cancel="cancel">

          <Input v-model="diqu" placeholder=""></Input>

        </Modal>
      </Row>
      <Row>
        <Col span="">
        <Table border :columns="columns7" :data="data6"></Table>
        </Col>
      </Row>
    </FormItem>
  </Form>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      diqu: "",
      psfs: "",
      modal1: false,
      modal2: false,
      columns7: [
        {
          title: "ID",
          key: "id",
          width: 100
        },
        {
          title: "地区名称",
          key: "name",
          render: (h, params) => {
            return h("div", [
              h("Icon", {
                props: {
                  type: "person"
                }
              }),
              h("strong", params.row.name)
            ]);
          }
        },
        {
          title: "操作",
          key: "id",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      let _self = this;
                      console.log(params);
                      // _self.deleteGroupArea(params.row.id)
                      // this.show(params.row.gdm_id);
                      $.ajax({
                        url: BASE_URL + "groupset/deleteGroupArea",
                        type: "get",
                        data: {
                          id: JSON.stringify(params.row.id)
                        },
                        success: function(res) {
                          console.log(res);
                          if (res) {
                            _self.getgroupAreas();
                          }
                        }.bind(this)
                      });
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      data6: [],
      columns8: [
        {
          title: "ID",
          key: "gdm_id",
          width: 100
        },
        {
          title: "配送方式",
          key: "name",
          render: (h, params) => {
            return h("div", [
              h("Icon", {
                props: {
                  type: "person"
                }
              }),
              h("strong", params.row.gdm_name)
            ]);
          }
        },
        {
          title: "操作",
          key: "id",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      let _self = this;
                      // this.show(params.id);
                      console.log(params.row.gdm_id);
                      $.ajax({
                        url: BASE_URL + "groupset/deleteGroupDeliveryMode",
                        type: "get",
                        data: {
                          id: params.row.gdm_id
                        },
                        success: function(res) {
                          if (res) {
                            _self.getgroupDeliveryModes();
                          }
                        }
                      });
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      data7: [],
      formItem: {
        input: "",
        select: "",
        radio: "male",
        checkbox: [],
        switch: true,
        date: "",
        time: "",
        slider: [20, 50],
        textarea: ""
      }
    };
  },
  created() {
    this.getgroupDeliveryModes();
    this.getgroupAreas();
  },
  methods: {
    cancel1() {
      this.modal1 = false;
    },
    cancel() {
      this.modal2 = false;
    },
    handleAdd() {
      console.log(this.tag);
      if (this.count.length) {
        this.count.push({ name: this.tag });
        console.log(this.count);
      } else {
        this.count.push(0);
      }
    },
    handleClose2(event, name) {
      const index = this.count.indexOf(name);
      this.count.splice(index, 1);
    },
    // ok() {
    //   this.$Message.info(this.diqu);
    //   this.diqu = "";
    // },
    // cancel() {
    //   this.$Message.info("Clicked cancel");
    // },
    getgroupDeliveryModes: function() {
      //获取配送方式集合
      $.ajax({
        url: BASE_URL + "groupset/groupDeliveryModes",
        type: "get",
        success: function(res) {
          console.log(res);
          this.data7 = res;
        }.bind(this)
      });
    },
    addModes: function() {},
    getgroupAreas: function() {
      $.ajax({
        url: BASE_URL + "groupset/groupAreas",
        type: "get",
        success: function(res) {
          console.log(res);
          this.data6 = res;
        }.bind(this)
      });
    },
    addAreas: function() {
      let data = {
        name: this.diqu,
        description: this.diqu,
        create_user: "root",
        update_user: "root",
        status: "1"
      };
      $.ajax({
        url: BASE_URL + "groupset/saveGroupArea",
        type: "post",
        data: {
          groupArea: JSON.stringify(data)
        },
        success: function(res) {
          this.getgroupAreas();
        }.bind(this)
      });
    },
    addPsfs: function() {
      // 添加配送方式
      let data = {
        gdm_create_user: "root",
        gdm_id: 1,
        gdm_name: this.psfs,
        gdm_status: "1"
      };
      $.ajax({
        url: BASE_URL + "groupset/saveGroupDeliveryMode",
        type: "post",
        data: {
          groupDeliveryMode: JSON.stringify(data)
        },
        success: function(data) {
          if (data) {
            this.getgroupDeliveryModes();
          }
        }.bind(this)
      });
    },
    deleteGroupArea: function(id) {
      $.ajax({
        url: BASE_URL + "groupset/deleteGroupArea",
        type: "post",
        data: {
          id: JSON.stringify(id)
        },
        success: function(res) {
          console.log(res);
          if (res) {
            this.getgroupAreas();
          }
        }.bind(this)
      });
    }
  }
};
</script>

<style scoped >
</style>
